package com.sky.controller.admin;

import com.sky.result.Result;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.data.redis.core.ValueOperations;
import org.springframework.web.bind.annotation.*;

@RestController("AdminShop")
@RequestMapping("/admin/shop")
@Api("店铺相关注解")
@Slf4j
public class ShopController {
    public static final String KEY ="status";

    @Autowired
    private RedisTemplate redisTemplate;

    /**
     * 获取店铺状态
     * @return
     */
    @ApiOperation("获取店铺营业状态")
    @GetMapping("/status")
    public Result<Integer> status(){
        ValueOperations valueOperations = redisTemplate.opsForValue();
        Integer status =(Integer) valueOperations.get(KEY);
        if(status==null){
            return Result.error("获取数据错误");
        }
        return Result.success(status);
    }

    /**
     * 设置店铺状态
     */
    @ApiOperation("设置店铺状态")
    @PutMapping("/{status}")
    public Result changeStatus(@PathVariable Integer status){
        ValueOperations valueOperations = redisTemplate.opsForValue();
        valueOperations.set(KEY,status);
        //log.info("营业状态为：{}",status==1?"营业中":"打烊中");
        return Result.success("修改营业状态成功");
    }


}
